package com.maimao.model.order;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.*;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Id;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * @author MaoLin Wang
 * @date 2021/1/15 6:00 下午
 */
@Setter
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName("mm_order")
@Accessors(chain = true)
public class Order implements Serializable {

    private static final long serialVersionUID = -4021700330345745891L;
    /**
     * 订单id
     */
    @TableId(type = IdType.INPUT)
    private Long id;

    /**
     * 用户id
     */
    @TableField("user_id")
    private Long userId;

    /**
     * 收货人
     */
    @NotBlank(message = "请选择收货地址")
    private String consignee;

    @NotBlank(message = "请选择收货地址")
    private String mobile;

    @NotBlank(message = "请选择收货地址")
    @ExcelProperty("地址")
    private String address;

    /**
     * 系统优惠券id
     */
    @TableField("sys_coupon_id")
    @ExcelProperty("系统优惠券编号")
    private Long sysCouponId;

    /**
     * 积分总减免
     */
    @ExcelProperty("积分总减免")
    private BigDecimal integral;

    /**
     * 是否使用了积分
     */
    @TableField("use_integral")
    @ExcelProperty("是否使用了积分")
    private Boolean useIntegral;

    /**
     * 支付code
     */
    @TableField("pay_code")
    private String payCode;

    /**
     * 支付时间
     */
    @TableField("pay_time")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss", iso = DateTimeFormat.ISO.DATE_TIME)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime payTime;

    @TableField("create_time")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime createTime;

    /**
     * 订单取消时间
     */
    @TableField("close_time")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss", iso = DateTimeFormat.ISO.DATE_TIME)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime closeTime;

    /**
     * 订单状态(1-已提交-待付款，2-已付款-待发货， 3 -交易成功，4-交易取消 )
     */
    @TableField("`status`")
    @ExcelProperty("状态")
    private Integer status;

    /**
     * 1 普通订单 2秒杀订单
     */
    @TableField("type")
    @ExcelProperty("类型")
    private Integer type;

    @ExcelProperty("是否删除")
    private Boolean deleted;

    @Override
    public String toString() {
        return "Order{" +
                "id=" + id +
                ", userId=" + userId +
                ", consignee='" + consignee + '\'' +
                ", mobile='" + mobile + '\'' +
                ", address='" + address + '\'' +
                ", sysCouponId=" + sysCouponId +
                ", integral=" + integral +
                ", useIntegral=" + useIntegral +
                ", payCode='" + payCode + '\'' +
                ", payTime=" + payTime +
                ", createTime=" + createTime +
                ", closeTime=" + closeTime +
                ", deleted=" + deleted +
                ", type=" + type +
                '}';
    }
}
